<template>
	<view>
		<view class="top-bg">
			<text>CONTRA</text>
		</view>
		<view class="info-con">
			<view class="info">
				<view class="title">
					<text>签约记录</text>
					<text v-if="userInfo.status === 2" >已实名</text>
					<text v-if="userInfo.status !== 2" @click="realName" >点击实名</text>
					<button type="default" size="mini" hover-class="hbtn" @click="giftReceive">礼品领取</button>
				</view>
				<view class="name" :class="{mp: contractList.length === 1}">
					<view style="text-align: center;font-size: 28rpx;color: #ccc;" v-if="contractList.length == 0">暂无签约</view>
					<!-- <view class="list" v-for="item in contractList" :key="item.id" @click="navTo(item.id)">
						<text>{{ item.ordersn }}</text>
						<text :class="['status', {'red': item.status === 4}, {'yellow': item.status === 1}, {'green': item.status === 2}, {'gray': item.status === 0}, {'pay': item.status === 3}, {'invalid': item.status === 5}]">{{ item.status_test }}</text>
						<view class="iconfont icongengduo"></view>
					</view> -->
					
					<view class="list" v-for="item in contractList" :key="item.id" @click="navTo(item.id)">
						<view class="left">
							<text>{{ item.class_name }}</text>
							<text :class="['status', {'red': item.status === 4}, {'yellow': item.status === 1}, {'green': item.status === 2}, {'gray': item.status === 0}, {'pay': item.status === 3}, {'invalid': item.status === 5}]">{{ item.status_test }}</text>
							<view class="iconfont icongengduo"></view>
						</view>
						<view class="right">
							<text>发起时间</text>
							<text>{{ item.create_time }}</text>
						</view>
					</view>
					<!-- <view class="list" style="justify-content: space-between;">
						<view style="display: flex;">
							<text style="font-size: 26rpx;color: #808080;">该合同由</text>
							<text style="font-size: 26rpx;color: #eaca0d;">课程顾问Kevin</text>
							<text style="font-size: 26rpx;color: #808080;">发起</text>
						</view>
						<view style="font-size: 26rpx;color: #b5b5b5;">2020-01-01 18:00</view>
					</view> -->
				</view>
			</view>
		</view>
		<view class="btn" @click="navToUser">
			<Dbutton :btnTxt="btnTxt"></Dbutton>
		</view>
		
	</view>
</template>

<script>
	import Dbutton from '../../components/button.vue'
	import { customerList, clientSign } from '../../api/serviceApi.js'
	import { getUserState } from '../../api/indexApi.js'
	export default {
		data() {
			return {
				btnTxt: '返回个人中心',
				userInfo: {},
				params: {
					p: 1,
					length: ''
				},
				contractList: []
			}
		},
		onLoad() {
			this._getUserState() // 获取认证状态
			this._customerList() // 获取签约列表
		},
		onPullDownRefresh() {
			console.log('开启下la刷新了')
			this.params.p = 1
			this.contractList = []
			this.userInfo = {}
			setTimeout(() => {
				this._getUserState() // 获取实名状态
				this._customerList(() => {
					uni.stopPullDownRefresh()
				}) // 获取客户的签约列表
			}, 300)
		},
		onReachBottom() {
			if (this.contractList.length === this.total) return
			this.params.p ++
			this._customerList() // 获取客户的签约列表
		},
		methods: {
			async _getUserState() {
				const res = await getUserState()
				this.userInfo = res.data.data
				// console.log(this.userInfo)
			},
			realName() {
				// window.location.href = this.userInfo.url
				uni.navigateTo({
					url: '../real-name/real-name'
				})
			},
			async _customerList(callback) {
				const res = await customerList(this.params)
				console.log(res)
				// this.contractList = res.data.data.list
				this.contractList = [...this.contractList, ...res.data.data.list]
				this.total = res.data.data.total
				callback && callback()
			},
			navTo(id) {
				console.log(id)
				uni.navigateTo({
					url: `./mySignCustomer?id=${id}`
				})
			},
			navToUser() {
				// window.location.href = 'https://mobile.laiba.shop/html/#/pages/user/user'
				window.location.href = 'https://group.laiba.shop/app/index.php?r=&i=40&c=entry&m=renren_shop&do=wap#/pagesMember/index/index'
			},
			giftReceive() {
				uni.navigateTo({
					url: '../gift-verification/gift-verification'
				})
			}
		},
		components: {
			Dbutton
		},
	}
</script>

<style lang="scss" scoped>
	.top-bg {
		height: 300rpx;
		background-color: #fedb0d;
		background-size: 100%;
		text-align: center;
		text {
			font-size: 152rpx;
			font-weight: 800;
			color: rgba(255, 255, 255, .2);
		}
	}
	.info-con {
		font-family: PingFangSC-Regular;
		// height: 250rpx;
		position: relative;
		.info {
			position: absolute;
			left: 50%;
			top: -200rpx;
			transform: translateX(-50%);
			.title {
				display: flex;
				align-items: center;
				font-weight: 600;
				font-family: PingFangSC-Medium;
				color: #fff;
				padding-left: 4px;
				color: #191919;
				font-size: 34rpx;
				text:nth-child(2) {
					display: inline-block;
					// width: 77rpx;
					padding: 0 10rpx;
					height: 40rpx;
					background-color: #404040;
					border-radius: 24rpx;
					opacity: 0.8;
					font-family: PingFangSC-Regular;
					font-size: 18rpx;
					color: #fff;
					text-align: center;
					line-height: 40rpx;
					font-weight: normal;
					margin-left: 16rpx;
					margin-top: 2rpx;
					letter-spacing: 2rpx;
				}
				button {
					background-color: transparent;
					border: 1rpx solid #191919;
					line-height: 1.8;
					padding: 0 15rpx;
					color: #191919;
					border-radius: 30rpx;
					margin-right: 0;
				}
				.hbtn {
					opacity: 0.8;
				}
			}
			.name {
				box-sizing: border-box;
				width: 690rpx;
				min-height: 160rpx;
				// height: 400rpx;
				background-color: #fff;
				box-shadow: 0 8rpx 68rpx 0 rgba(0, 0, 0, 0.1);
				border-radius: 2rpx;
				display: flex;
				flex-direction: column;
				justify-content: space-around;
				margin-top: 36rpx;
				padding: 0 20rpx;
				margin-bottom: 160rpx;
				.list {
					display: flex;
					flex-direction: column;
					height: 160rpx;
					border-bottom: 1rpx solid #e6e6e6;
					font-family: PingFangSC-Regular;
					.left {
						display: flex;
						height: 130rpx;
						align-items: center;
						text:nth-child(1) {
							font-size: 30rpx;
							color: #191919;
							padding-left: 10rpx;
							display: flex;
							flex: 4;
						}
						.status {
							display: flex;
							// flex: 1;
							justify-content: center;
							align-items: center;
							padding: 2rpx 10rpx 4rpx 10rpx;
							border-radius: 4rpx;
							font-size: 24rpx;
							color: #808080;
							margin: 0 10rpx 0 16rpx;
						}
						.red {
							background-color: #ffede9;
							color: #f86442;
						}
						.yellow {
							background-color: #fff8cf;
							color: #ff9001;
						}
						.green {
							background-color: #ebfae0;
							color: #4eb307;
						}
						.gray {
							background-color: #f1f1f1;
							color: #9b9b9b;
						}
						.pay {
							background-color: #ffede9;
							color: #f86442;
						}
						.invalid {
							background-color: #f1f1f1;
							color: #9b9b9b;
						}
						.icongengduo {
							color: #808080;
							font-size: 26rpx;
						}
					}
					.right {
						font-family: PingFangSC-Regular;
						font-size: 20rpx;
						color: #ccc;
						padding-left: 10rpx;
						display: flex;
						justify-content: space-between;
						padding-bottom: 20rpx;
					}
				}
				.list:last-child {
					border-bottom: none;
				}
			}
			.mp {
				margin-top: 72rpx;
			}
		}
	}
	.btn {
		position: fixed;
		bottom: 34rpx;
		left: 0;
		right: 0;
	}
</style>
